package com.ximalaya.demo;

/**
 * Time: 2022/3/29 2:57 下午
 * Author: leixun
 * Email: leixun33@163.com
 * <p>
 * Description:
 */
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import androidx.viewpager.widget.ViewPager;

public class ControlViewpager extends ViewPager
{
    private boolean canGoLeft = true;
    private boolean canGoRight = true;
    private float c;
    private boolean d = true;
    private ClickListener clickListener;

    public ControlViewpager(Context paramContext)
    {
        super(paramContext);
    }

    public ControlViewpager(Context paramContext, AttributeSet paramAttributeSet)
    {
        super(paramContext, paramAttributeSet);
    }

    private boolean isSuperOnTouchEvent(MotionEvent paramMotionEvent)
    {
        try
        {
            boolean bool = super.onTouchEvent(paramMotionEvent);
            return bool;
        }
        catch (IllegalArgumentException exception)
        {
            exception.printStackTrace();
            Log.d("kid", "������������������4");
        }
        return false;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent paramMotionEvent)
    {
        try
        {
            boolean bool = super.onInterceptTouchEvent(paramMotionEvent);
            return bool;
        }
        catch (IllegalArgumentException exception)
        {
            exception.printStackTrace();
            Log.d("kid", "IllegalArgumentException���������");
        }
        return false;
    }

    @Override
    public boolean onTouchEvent(MotionEvent paramMotionEvent)
    {
        int eventAction = paramMotionEvent.getAction();
        int j = MotionEvent.ACTION_DOWN;
        if (eventAction != MotionEvent.ACTION_DOWN) {
            if (eventAction != MotionEvent.ACTION_UP) {
                if (eventAction != MotionEvent.ACTION_MOVE) {
                    eventAction = j;
                } else if (paramMotionEvent.getX() - this.c < 0.0F) {
                    eventAction = MotionEvent.ACTION_MOVE;
                } else {
                    eventAction = MotionEvent.ACTION_UP;
                }
            } else {
                this.d = true;
                eventAction = j;
                if (paramMotionEvent.getX() - this.c == 0.0F) {
                    ClickListener locala = this.clickListener;
                    eventAction = j;
                    if (locala != null) {
                        locala.onClick();
                        eventAction = j;
                    }
                }
            }
        } else {
            this.d = false;
            this.c = paramMotionEvent.getX();
            eventAction = j;
        }
        boolean bool;
        if (this.d) {
            bool = isSuperOnTouchEvent(paramMotionEvent);
            return bool;
        }
        if ((eventAction == MotionEvent.ACTION_MOVE) && (this.canGoRight)) {
            bool = isSuperOnTouchEvent(paramMotionEvent);
            return bool;
        }
        if ((eventAction == MotionEvent.ACTION_UP) && (this.canGoLeft)) {
            bool = isSuperOnTouchEvent(paramMotionEvent);
            return bool;
        }
        return true;
    }

    public void setCanGoLeft(boolean paramBoolean)
    {
        this.canGoLeft = paramBoolean;
    }

    public void setCanGoRight(boolean paramBoolean)
    {
        this.canGoRight = paramBoolean;
    }

    public void setClickListener(ClickListener parama)
    {
        this.clickListener = parama;
    }

    public static abstract interface ClickListener
    {
        public abstract void onClick();
    }
}

